package com.syz.web.service.Impl;

import com.syz.web.dao.IBanjiDao;
import com.syz.web.dao.Impl.BanjiDaoImpl;
import com.syz.web.pojo.Banji;
import com.syz.web.pojo.vo.BanjiCountVO;
import com.syz.web.service.IBanjiService;
import com.syz.web.util.PageInfo;

import java.util.List;

public class BanjiServiceImpl implements IBanjiService {
    private IBanjiDao banjiDao = new BanjiDaoImpl();


    @Override
    public PageInfo<Banji> selectByPage(Integer pageNo, Integer pageSize) {
        List<Banji> list = banjiDao.selectByPage(pageNo, pageSize);
        Integer totalCount = banjiDao.selectTotalCount();
        int totalPage = (int)Math.ceil((double)totalCount / pageSize);
        PageInfo<Banji> pageInfo = new PageInfo<>(list, totalPage, pageNo, pageSize);
        return pageInfo;
    }

    @Override
    public boolean deleteById(int id) {
        int count = banjiDao.deleteById(id);
        return count == 1 ? true : false;
    }

    @Override
    public boolean add(String name) {
        int count=banjiDao.add(name);
        return count>0?true:false;
    }

    @Override
    public boolean update(String id, String name) {
        int count=banjiDao.update(id,name);
        return count>0?true:false;
    }

    @Override
    public Banji getBanjiUpdatePage(String id) {
        return banjiDao.getBanjiUpdatePage(id);
    }

    @Override
    public List<BanjiCountVO> selectBanjiCount() {
        return banjiDao.selectBanjiCount();
    }

    @Override
    public List<Banji> selectAll() {
        return banjiDao.selectAll();
    }
}
